package edu.umd.mhealth.views;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.model.XYValueSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;


public class WeightHistoryView extends View {
	

	private static XYMultipleSeriesDataset dataset;
	private static XYMultipleSeriesRenderer mRenderer;
	private static GraphicalView v;
	
	
	public WeightHistoryView(Context context, double[] series) {
		super(context);
		dataset = getDataset(series);
		mRenderer = getDemoRenderer();
		v = ChartFactory.getBarChartView(context, dataset, mRenderer, Type.DEFAULT);
		return;
	}
	
	public GraphicalView getGraph(){
		return v;
	}
	
	
	private static XYMultipleSeriesDataset getDataset(double[] series) {
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        XYValueSeries firstSeries = new XYValueSeries("");
        for (int i = 0; i < 7; i++)
            firstSeries.add(i, series[i]);
        dataset.addSeries(firstSeries);
        return dataset;
    }
 
    private static XYMultipleSeriesRenderer getDemoRenderer() {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        renderer.setMargins(new int[] { 0, 0, 0, 0 });
        renderer.setShowLegend(false);
        renderer.setMarginsColor(Color.WHITE);
        renderer.setScale(2);
        renderer.setXAxisMax(7);
        renderer.setXAxisMin(-1);
        renderer.setYAxisMin(0);
        renderer.setYAxisMax(200);
        renderer.setBarSpacing(.35);
        renderer.setBackgroundColor(Color.BLUE);
        
        XYSeriesRenderer r = new XYSeriesRenderer();
        r.setColor(Color.rgb(0, 109, 176));
        r.setLineWidth(4);
        r.setPointStyle(PointStyle.SQUARE);
        r.setFillPoints(true);
        r.setDisplayChartValues(true);

        renderer.addSeriesRenderer(r);
        return renderer;
    }
    
  
 
}
